package com.newcapec.lesson1;

import java.util.Objects;

public class Student extends Person {
    private int stuId;

    public Student() {
        super();
    }


    public Student(String name, String sex, int age, int stuId) {
        super(name, sex, age);
        this.stuId = stuId;
    }

    public Student(Student student){
        super(student);
        this.stuId = student.stuId;

    }

    /**
     * 只要内容一致(姓名、年龄、性别、学号)，结果为true
     *
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        // == 比较的是字面量
        if (this == o) {
            return true;
        }
        //此时地址不一样，需要查看内容是否一致
        if (o instanceof Student) {
            //判断具体内容
            Student stu = (Student) o;
            if(super.equals(stu) &&
                    this.getStuId() == stu.getStuId()){
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(stuId);
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    @Override
    public String toString() {
        return "Student{" + super.toString() +
                "stuId=" + stuId +
                '}';
    }
}
